<?php

	require_once('../config.php');
	include_once("../database/DataBase.php");
	include_once("../include/function.php");
				
	session_start();
	checkLogin();
	
	$database = New DataBase();
	$database->open_connection();
	$typeList = $database->getUserType($_SESSION["user_type"]);
	
	$user_id = decrypt_string($_GET["key"]);
	if(strlen(trim($user_id)) == 0){
		$user_id = $_SESSION["login_id"];
	}
	$result = $database->getUserByLoginID($user_id);
	$user = mysql_fetch_assoc($result);
	
?>
<!DOCTYPE html>
<html>
	<head>
	<title>CMS</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<?
			include_once("../include/includeHeader.php");
		?>

		<script>
		$(function() {
			$( "#birthday" ).datepicker({
				changeMonth: true,
				changeYear: true
			});
		});
		</script>
	</head>
	
	<body>
			<?php
				include_once("../include/top_navigation.php");
			?>
			<div Class="Middle">
				<div class="LeftMenu">
					<?php include_once("../include/left_menu.php"); ?>
				</div>
				<div id="RightContent" >
					<h2>Update User</h2>
					<form name="newUser" method="POST" action="../include/user_edit_process.php">
						<table class="userForm">
							<tr>
								<td colspan="2"><div name="message" id="message" ></div></td>
							</tr>
							<tr>
								<td>Login name : </td>
								<td><input type="text" name="user_id" id="user_id" readonly="readonly" value="<?php echo $user_id;?>"/></td>
							</tr>
							<tr>
								<td>Email : </td>
								<td>
									<input type="hidden" name="old_email" id="old_email" value="<?php echo $user["email"];?>" />
									<input type="text" name="email" id="email" value="<?php echo $user["email"];?>">
								</td>
							</tr>
							
							<tr>
								<td>First name : </td>
								<td><input type="text" name="firstname" id="firstname" value="<?php echo $user["firstname"];?>"></td>
							</tr>
							<tr>
								<td>Last name : </td>
								<td><input type="text" name="lastname" id="lastname" value="<?php echo $user["lastname"];?>"></td>
							</tr>
							<tr>
								<td>Contact No : </td>
								<td><input type="text" name="contact_no" id="contact_no" value="<?php echo $user["contact_no"];?>"></td>
							</tr>
							<tr>
								<td>User Type : </td>
								<td>

									<select name="type" id="type" >
										<option value=""> -- </option>
										<?php
											while ($row = mysql_fetch_assoc($typeList)) {
												if($user["type"] == $row["type"]){
													echo "<option value=\"".$row["type"]."\" selected>".$row["description"]."</option>";
												}
												else{
													echo "<option value=\"".$row["type"]."\">".$row["description"]."</option>";
												}
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Address : </td>
								<td><input type="text" name="address" id="address" value="<?php echo $user["address"];?>"></td>
							</tr>
							<tr>
								<td>Birthday : </td>
								<td><input type="text" name="birthday" value="<?php echo $user["birthday"];?>" placeholder="DD/MM/YYYY" id="birthday"></td>
							</tr>
							<tr>
								<td>Note : </td>
								<td><textarea name="note" id="note" rows="4" cols="50"><? echo $user["note"];?></textarea></td>
							</tr>
							<tr>
								<td colspan="2"><input type="button" name="click_button" value="Update" onclick="javascript: checkUpdateForm(document.newUser);" /></td>
							</tr>
						</table>
						
						
					</form>
				</div>
			</div>
			<?php
				include_once("../include/footer.php");
			?>
		
	</body>
</html>

<?
	$database->close_connection();
?>